package com.greenant.store.bean;

import android.text.TextUtils;

import com.avos.avoscloud.AVACL;
import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVRelation;

import java.util.Date;
import java.util.Random;

/**
 * 代收
 * 
 * @author 1mf2
 *
 */
@AVClassName(AntAVObject.CLASS_EMRECV)
public class EMRecv extends AntAVObject {

	// 已出库
	public static final int EMRECV_TYPE_EXPORT = 2;
	// 已入库
	public static final int EMRECV_TYPE_INPORT = 1;

	public static final String STATUS = "status";// number 0-无意义 1-代取，2-已取
	public static final String CREATEDAT = "createdAt"; // DATE 收件时间（系统的创建时间）
	public static final String SINGEDTIME = "SingedTime";// DATE 签收时间
	public static final String USERID = "userId";// string 收件人的objectId
	public static final String SINGER = "singer";// string 签收人
	public static final String ORDERID = "orderId"; // string 订单号（保留）
	public static final String EMID = "EMId"; // string 快递单号
	public static final String EMCODE = "EMCode"; // string 提货码
	public static final String STORE = "store";// relation 代收点的商店
	public static final String EMCOMPANY = "EMCompany";// string 快递公司
	public static final String SENDERNAME = "senderName";// string 发件人姓名
	public static final String SENDERPHONE = "senderPhone";// phone 发件人电话
	public static final String SENDERADDR = "senderAddr";// string 发件人地址
	public static final String RECEIVERNAME = "receiverName"; // string 收件人姓名
	public static final String RECEIVERPHONE = "receiverPhone"; // string 收件人电话
	public static final String RECEIVERADDR = "receiverAddr"; // string 收件人地址
	
	
	/**
	 * 用来设置电话和订单二维码是否已经设置的标志
	 */
	private boolean isSet=false;

	private EMCompany eMCompany;
	public EMRecv() {
		super();
		setAccessCtrl();
		TAG = getObjectId();
		if (TextUtils.isEmpty(TAG)) {
			TAG = String.valueOf(System.currentTimeMillis() + Math.random());
		}
	}

	public EMRecv(String str) {
		super(str);
		setAccessCtrl();
		TAG = getObjectId();
		if (TextUtils.isEmpty(TAG)) {
			TAG = String.valueOf(System.currentTimeMillis() + Math.random());
		}
	}

	public EMRecv getInstance() {
		return this;
	}

	public String getUserId() {
		return this.getString(USERID);
	}

	public void setUserId(String userId) {
		this.put(USERID, userId);
	}
	
	public String getSinger() {
		return this.getString(SINGER);
	}

	public void setSinger(String userId) {
		this.put(SINGER, userId);
	}
	
	public String getOrderId() {
		return this.getString(ORDERID);
	}

	public void setOrderId(String userId) {
		this.put(ORDERID, userId);
	}
	
	public String getEMId() {
		return this.getString(EMID);
	}

	public void setEMId(String userId) {
		this.put(EMID, userId);
	}
	
	public String getEMCode() {
		return this.getString(EMCODE);
	}

	public void setEMCode(String userId) {
		this.put(EMCODE, userId);
	}

	public AVRelation<StoreInfo> getStoreRelation()
    {
        return this.getRelation(STORE);
    }
    public void removeStoreRelation(StoreInfo goods)
    {       
        this.getRelation(STORE).remove(goods);
    }
	
	public EMCompany getEMCompany() {
		return eMCompany;
	}
	
	public void setEMCompany(EMCompany emcompany) {
         this.eMCompany=emcompany;
    }
	
	public String getSenderName() {
		return this.getString(SENDERNAME);
	}

	public void setSenderName(String userId) {
		this.put(SENDERNAME, userId);
	}
	
	public String getSenderPhone() {
		return this.getString(SENDERPHONE);
	}

	public void setSenderPhone(String userId) {
		this.put(SENDERPHONE, userId);
	}
	
	public String getSenderAddr() {
		return this.getString(SENDERADDR);
	}

	public void setSenderAddr(String userId) {
		this.put(SENDERADDR, userId);
	}
	
	public String getReceiverName() {
		return this.getString(RECEIVERNAME);
	}

	public void setReceiverName(String userId) {
		this.put(RECEIVERNAME, userId);
	}
	
	public String getReceiverPhone() {
		return this.getString(RECEIVERPHONE);
	}

	public void setReceiverPhone(String userId) {
		this.put(RECEIVERPHONE, userId);
	}
	
	public String getReceiverAddr() {
		return this.getString(RECEIVERADDR);
	}

	public void setReceiverAddr(String userId) {
		this.put(RECEIVERADDR, userId);
	}
	
	public int getStatus() {
		return this.getInt(STATUS);
	}

	public void setStatus(int userId) {
		this.put(STATUS, userId);
	}
	
	public Date getSingedTime() {
		return this.getDate(SINGEDTIME);
	}

	public void setSingedTime(Date userId) {
		this.put(SINGEDTIME, userId);
	}
	
	private int setAccessCtrl() {

		acl = new AVACL();
		acl.setPublicReadAccess(true);// �˴����õ��������˵Ŀɶ�Ȩ��
		acl.setPublicWriteAccess(true);
		this.setACL(acl);

		return 0;
	}
	
	private String TAG = null;

	public String getTag() {
		return TAG;
	}
	

    public boolean isSet() {
        if (!TextUtils.isEmpty(getEMId()) &&isPhoneSet() )
            return true;
        return false;
    }
    
	public boolean isPhoneSet() {
		if (!TextUtils.isEmpty(getReceiverPhone()) && TextUtils.isDigitsOnly(getReceiverPhone())
				&& getReceiverPhone().length() == 11) {
			return true;
		}
		return false;
	}
    

}
